package com.example.soss.util;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.TimeUnit;


/**
 **限流工具类
 */
public class AccessLimitUtil {
    //限流
    private static final RateLimiter pageRateLimiter = RateLimiter.create(400);
    private static final RateLimiter selectRateLimiter = RateLimiter.create(50);

    public static boolean pageTryAcquire() {
        return pageRateLimiter.tryAcquire();
    }

    public static boolean pageTryAcquire (long timeout, TimeUnit unit) {
        return pageRateLimiter.tryAcquire(timeout, unit);
    }

    public static boolean selectTryAcquire() {
        return selectRateLimiter.tryAcquire();
    }

    public static boolean selectTryAcquire (long timeout, TimeUnit unit) {
        return selectRateLimiter.tryAcquire(timeout, unit);
    }

}
